cmake_minimum_required(VERSION 3.5.0)
project(MoonlightOH)

set(CMAKE_CXX_STANDARD 26)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument -Wno-format")

include(thirdparty/ohos-openssl/prelude/${OHOS_ARCH}/lib/cmake/OpenSSL/OpenSSLConfig.cmake)
add_subdirectory(thirdparty/moonlight-common-c-ohos)
add_subdirectory(thirdparty/opus)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

if(DEFINED PACKAGE_FIND_FILE)
    include(${PACKAGE_FIND_FILE})
endif()

include_directories(
    ${NATIVERENDER_ROOT_PATH}
    ${NATIVERENDER_ROOT_PATH}/include
)

add_library(moonlight-core-runtime STATIC
    core/utils/mkcert.cpp
    core/utils/CertificateEnvironment.cpp
    core/utils/NapiUtils.cpp
    core/utils/XComponentUtils.cpp
    core/utils/AVUtils.cpp
    core/utils/CancellableTimer.cpp
    core/gamestream/GameStreamManager.cpp
    core/gamestream/XComponentBackend.cpp
    core/gamestream/XComponentCallbacks.cpp
    core/gamestream/video/VideoProcessor.cpp
    core/gamestream/video/LimelightVideoCallbacks.cpp
    core/gamestream/video/VideoDecoderCallbacks.cpp
    core/gamestream/video/VideoStatsImpl.cpp
    core/gamestream/audio/AudioProcessor.cpp
    core/gamestream/audio/PcmBufferSpan.cpp
    core/gamestream/audio/LimelightAudioCallbacks.cpp
    core/gamestream/audio/AudioRendererCallbacks.cpp
    core/gamestream/control/touch_screen/AbstractTouchScreenControlHandler.cpp
    core/gamestream/control/touch_screen/PassThroughController.cpp
    core/gamestream/control/touch_screen/TrackpadEmulator.cpp
    core/gamestream/control/mouse/MouseController.cpp
    core/gamestream/control/keyboard/KeyboardController.cpp
)
target_include_directories(moonlight-core-runtime PRIVATE
    ${Opus_PUBLIC_HEADER}
)
target_link_libraries(moonlight-core-runtime PUBLIC
    hilog_ndk.z
    ace_ndk.z
    ace_napi.z
    uv
    native_media_codecbase
    native_media_core
    native_media_vdec
    native_window
    native_media_acodec
    ohaudio
    OpenSSL::SSL
    OpenSSL::Crypto
    opus
    moonlight-common-c
)

add_library(entry SHARED types/libentry/napi_init.cpp)
target_link_libraries(entry PRIVATE moonlight-core-runtime)

add_library(gamestream_xcomponent SHARED types/libgamestream_xcomponent/napi_init.cpp)
target_link_libraries(gamestream_xcomponent PRIVATE moonlight-core-runtime)
